﻿using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web.Mvc;
using RotaractProjectCalendar.DataAccessLayer;

namespace RotaractProjectCalendar.Areas.Anonymous.Controllers
{
    [AllowAnonymous]
    public class ClubController : Controller
    {
        private readonly CalendarContext _db = new CalendarContext();

        //
        // GET: /Club/
        public async Task<ActionResult> Index()
        {
            var clubs = _db.Clubs.Select(c => c);

            return View(await clubs.ToListAsync());
        }

        //
        // GET: /Club/Details/5
        public async Task<ActionResult> Details(int? id)
        {
            if(id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var club = await _db.Clubs.FindAsync(id);
            if(club == null)
            {
                return HttpNotFound();
            }
            return View(club);
        }

        protected override void Dispose(bool disposing)
        {
            if(disposing)
            {
                _db.Dispose();
            }
            base.Dispose(disposing);
        }
	}
}